package com.xfcy.blog.valid;

import io.swagger.models.auth.In;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @author 晓风残月Lx
 * @date 2023/4/20 23:58
 */
public class SimpleValueConstraintValidator implements ConstraintValidator<SimpleValue, String> {

    private Long simpleValue = null;

    /**
     * 初始化方法
     * @param constraintAnnotation annotation instance for a given constraint declaration
     */
    @Override
    public void initialize(SimpleValue constraintAnnotation) {
        simpleValue = constraintAnnotation.value();
    }


    /**
     * 判断是否检验成功
     * @param value object to validate  是注解标注地方传过来的值 也就是需要验证的值
     * @param context context in which the constraint is evaluated
     *
     * @return
     */
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return simpleValue == value.length();
    }
}
